﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="NavigationViewModel.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the NavigationViewModel type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Client.Common.BaseClasses
{
    using System;
    using System.Windows.Input;
    using Microsoft.Practices.Prism.Commands;
    using Microsoft.Practices.Prism.Regions;
    using Microsoft.Practices.ServiceLocation;

    /// <summary>
    ///  Defines the <seealso cref="NavigationViewModel"/> type.
    /// </summary>
    public class NavigationViewModel : ViewModelBase
    {
        /// <summary>
        /// Member variable _selectedCommand
        /// </summary>
        private ICommand _selectedCommand;

        /// <summary>
        /// Gets the selected command.
        /// </summary>
        /// <value>The selected command.</value>
        public ICommand SelectedCommand
        {
            get
            {
                if (this._selectedCommand == null)
                {
                    this._selectedCommand = new DelegateCommand(this.OnSelected);
                }

                return this._selectedCommand;
            }
        }

        /// <summary>
        /// Gets or sets the last navigated URI.
        /// </summary>
        /// <value>The last navigated URI.</value>
        protected Uri LastNavigatedUri { get; set; }

        /// <summary>
        /// Called when [selected].
        /// </summary>
        protected virtual void OnSelected()
        {
            if (LastNavigatedUri != null)
            {
                var regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
                regionManager.RequestNavigate(Regions.WorkspaceRegion, LastNavigatedUri);
            }
        }
    }
}